package com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.util.MessageResources;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.articles.bo.ITArticlesManage;
import com.tjsinfo.tjsoa.common.DealString;
import com.tjsinfo.tjsoa.common.FileManage;
import com.tjsinfo.tjsoa.common.PaginationSupport;
import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.common.TestRiQi;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenBeizhuBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenFujianBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenYijianBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenZhengwenBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawendengjibuBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.IWenTypeBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.MainType;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.SubTypeInfo;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenBeizhu;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenFujian;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenNeirong;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenYijian;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenZhengwen;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawendengjibu;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TaoHongMoBan;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.YinZhang;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.vo.TXingzhengshouwenNeirong;
import com.tjsinfo.tjsoa.mail.bo.ITjsemailReceivedBo;
import com.tjsinfo.tjsoa.mail.bo.ITjsmailBo;
import com.tjsinfo.tjsoa.system.bo.IDepartmentBo;
import com.tjsinfo.tjsoa.system.bo.ILianDongBO;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserDepartmentBo;
import com.tjsinfo.tjsoa.system.vo.Files;
import com.tjsinfo.tjsoa.system.vo.LianDong;
import com.tjsinfo.tjsoa.system.vo.TSystemDepartment;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDepartment;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workflow.Taskinstance;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;
import com.tjsinfo.tjsoa.workflow.bo.ITaskInstanceBO;

public class ShenPiAction extends DispatchAction{
	private ITXingzhengfawenNeirongBO xingzhengfawenNeirongBO;
	private ITXingzhengfawenFujianBO xingzhengfawenFujianBO;
	private ITXingzhengfawenZhengwenBO xingzhengfawenZhengwenBO;
	private ITXingzhengfawenBeizhuBO xingzhengfawenBeizhuBO;
	private ITXingzhengfawenYijianBO xingzhengfawenYijianBO;
	private ISystemUserBo systemUserBo;
	private IDepartmentBo departmentBo;
	private ITXingzhengfawendengjibuBO xingzhengfawendengjibuBO;
	private ISystemUserDepartmentBo systemUserDepartmentBo;
	private ITaskInstanceBO taskInstanceBO;
	private  ITjsmailBo tjsmailBo;
	private  ITjsemailReceivedBo tjsemailReceivedBo;
	private ILianDongBO lianDongBO;
	private IWenTypeBO wenTypeBO;
	
	public ITXingzhengfawenBeizhuBO getXingzhengfawenBeizhuBO() {
		return xingzhengfawenBeizhuBO;
	}

	public void setXingzhengfawenBeizhuBO(
			ITXingzhengfawenBeizhuBO xingzhengfawenBeizhuBO) {
		this.xingzhengfawenBeizhuBO = xingzhengfawenBeizhuBO;
	}

	public IWenTypeBO getWenTypeBO() {
		return wenTypeBO;
	}
	
	public void setWenTypeBO(IWenTypeBO wenTypeBO) {
		this.wenTypeBO = wenTypeBO;
	}
	
	public ILianDongBO getLianDongBO() {
		return lianDongBO;
	}
	public void setLianDongBO(ILianDongBO lianDongBO) {
		this.lianDongBO = lianDongBO;
	}
	public ITjsmailBo getTjsmailBo() {
		return tjsmailBo;
	}
	public void setTjsmailBo(ITjsmailBo tjsmailBo) {
		this.tjsmailBo = tjsmailBo;
	}
	public ITjsemailReceivedBo getTjsemailReceivedBo() {
		return tjsemailReceivedBo;
	}
	public void setTjsemailReceivedBo(ITjsemailReceivedBo tjsemailReceivedBo) {
		this.tjsemailReceivedBo = tjsemailReceivedBo;
	}
	public IDepartmentBo getDepartmentBo() {
		return departmentBo;
	}
	public void setDepartmentBo(IDepartmentBo departmentBo) {
		this.departmentBo = departmentBo;
	}
	public ISystemUserDepartmentBo getSystemUserDepartmentBo() {
		return systemUserDepartmentBo;
	}
	public void setSystemUserDepartmentBo(
			ISystemUserDepartmentBo systemUserDepartmentBo) {
		this.systemUserDepartmentBo = systemUserDepartmentBo;
	}
	public ITaskInstanceBO getTaskInstanceBO() {
		return taskInstanceBO;
	}
	public void setTaskInstanceBO(ITaskInstanceBO taskInstanceBO) {
		this.taskInstanceBO = taskInstanceBO;
	}
	
	public ITXingzhengfawenNeirongBO getXingzhengfawenNeirongBO() {
		return xingzhengfawenNeirongBO;
	}
	public void setXingzhengfawenNeirongBO(
			ITXingzhengfawenNeirongBO xingzhengfawenNeirongBO) {
		this.xingzhengfawenNeirongBO = xingzhengfawenNeirongBO;
	}
	public ITXingzhengfawenFujianBO getXingzhengfawenFujianBO() {
		return xingzhengfawenFujianBO;
	}
	public void setXingzhengfawenFujianBO(
			ITXingzhengfawenFujianBO xingzhengfawenFujianBO) {
		this.xingzhengfawenFujianBO = xingzhengfawenFujianBO;
	}
	public ITXingzhengfawenYijianBO getXingzhengfawenYijianBO() {
		return xingzhengfawenYijianBO;
	}
	public void setXingzhengfawenYijianBO(
			ITXingzhengfawenYijianBO xingzhengfawenYijianBO) {
		this.xingzhengfawenYijianBO = xingzhengfawenYijianBO;
	}
	public ITXingzhengfawenZhengwenBO getXingzhengfawenZhengwenBO() {
		return xingzhengfawenZhengwenBO;
	}

	public void setXingzhengfawenZhengwenBO(
			ITXingzhengfawenZhengwenBO xingzhengfawenZhengwenBO) {
		this.xingzhengfawenZhengwenBO = xingzhengfawenZhengwenBO;
	}

	/**
	 * 员工行政发文拟稿   update by wjj
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward nigao(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		MessageResources message=getResources(arg2);
		//提交上传附件
		String fromFilePath=message.getMessage(arg2.getLocale(), "system.uploadFile.tempFilePath");
		String toFilePath = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengfawen/properties/systemResource.properties", this).getProperty("xingzhengfawen.fileurl");
		List<Files> fileList=DealString.fileCopyTofile(arg2, fromFilePath, toFilePath);
		
		TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
		xingzhengfawenNeirong.setBiaoti(arg2.getParameter("zhaiyao"));
		xingzhengfawenNeirong.setBiaoti(xingzhengfawenNeirong.getBiaoti().replace("<", "&lt;"));
		xingzhengfawenNeirong.setBiaoti(xingzhengfawenNeirong.getBiaoti().replace(">", "&gt;"));
		xingzhengfawenNeirong.setBiaoti(xingzhengfawenNeirong.getBiaoti().replace("\r\n", "<br/>"));
		xingzhengfawenNeirong.setChaosong(arg2.getParameter("chaosongname"));
	    xingzhengfawenNeirong.setZhusong(arg2.getParameter("zhusongname"));
	    xingzhengfawenNeirong.setState(1);		
		xingzhengfawenNeirong.setDocname(arg2.getParameter("docname"));
		xingzhengfawenNeirong.setZhuangta("0");
		
		if (arg2.getParameter("fujian") != null && !"".equals(arg2.getParameter("fujian"))) {
			xingzhengfawenNeirong.setFujian(arg2.getParameter("fujian"));
		}else{
			xingzhengfawenNeirong.setFujian("");
		}
		
		xingzhengfawenNeirong.setFujian(xingzhengfawenNeirong.getFujian().replace("<", "&lt;"));
		xingzhengfawenNeirong.setFujian(xingzhengfawenNeirong.getFujian().replace(">", "&gt;"));
		xingzhengfawenNeirong.setZhutici(arg2.getParameter("zhutici"));
		xingzhengfawenNeirong.setNigaorenid(SessionUser.getUserId(arg2));
		xingzhengfawenNeirong.setNigaorenname(SessionUser.getUser(arg2).getUsername());
		List<TSystemUserDepartment> systemUserDepartmentList = systemUserDepartmentBo.selectByUserId(SessionUser.getUserId(arg2));
		if (systemUserDepartmentList.size() > 0) {
			xingzhengfawenNeirong.setChengbanbumen(systemUserDepartmentList.get(0).getDepartmentName());
		} else {
			xingzhengfawenNeirong.setChengbanbumen("");
		}
		String hegaorenid = arg2.getParameter("hegaorenid");

		//伪代码
		long startTime=System.currentTimeMillis();   //获取开始时间
		String docid = xingzhengfawenNeirongBO.addTXingzhengfawenneirong(xingzhengfawenNeirong, hegaorenid,
		arg2.getParameter("bumenhuiqianid"),arg2.getParameter("zhusongid"), arg2.getParameter("chaosongid"),fileList);
		for (Files files : fileList) {
			ToolKit.copyFile(files.toFilePath, arg2.getSession().getServletContext().getRealPath("/") + "\\"+ "documentationflow\\xingzhengfawen\\docs\\"+files.getNewFileName());
		}
		long endTime=System.currentTimeMillis(); //获取结束时间
		Logger logger = Logger.getLogger(ShenPiAction.class);
		logger.log(Level.ERROR, "添加发文内容时间" + Long.valueOf(endTime-startTime));
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());			
		endTime=System.currentTimeMillis(); //获取结束时间
		logger.log(Level.ERROR, "总时间" + Long.valueOf(endTime-startTime));
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		
		arg2.setAttribute("flowid", xingzhengfawenNeirong.getId());
		addXingzhengfawenyijianks(arg2,"开始"); 
		
		return arg0.findForward("success");
	}
	
	
	public ActionForward qianfanigao(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		MessageResources message=getResources(arg2);
		//提交上传附件
		String fromFilePath=message.getMessage(arg2.getLocale(), "system.uploadFile.tempFilePath");
		String toFilePath = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengfawen/properties/systemResource.properties", this).getProperty("xingzhengfawenff.fileurl");
		List<Files> fileList=DealString.fileCopyTofile(arg2, fromFilePath, toFilePath);
		
		TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
		xingzhengfawenNeirong.setBiaoti(arg2.getParameter("zhaiyao"));
		xingzhengfawenNeirong.setBiaoti(xingzhengfawenNeirong.getBiaoti().replace("<", "&lt;"));
		xingzhengfawenNeirong.setBiaoti(xingzhengfawenNeirong.getBiaoti().replace(">", "&gt;"));
		xingzhengfawenNeirong.setBiaoti(xingzhengfawenNeirong.getBiaoti().replace("\r\n", "<br/>"));
		xingzhengfawenNeirong.setChaosong(arg2.getParameter("chaosongname"));
		
		String txzhusongidname=arg2.getParameter("txzhusongidname");
		String zhusongname=arg2.getParameter("zhusongname");
		String zhusong="";
		boolean a=txzhusongidname.contains("、");
		boolean aa=txzhusongidname.endsWith("、");
		if(zhusongname!=null&&zhusongname.length()!=0){
			if(txzhusongidname!=null&&txzhusongidname.length()!=0){
				if(a==true){
					if(aa==true){
						zhusong=txzhusongidname+zhusongname;
					}else{
						zhusong=txzhusongidname+"、"+zhusongname;
					}
					xingzhengfawenNeirong.setZhusong(zhusong);
				}else{
					zhusong=txzhusongidname+"、"+zhusongname;
					xingzhengfawenNeirong.setZhusong(zhusong);
				}
			}else{//txzhusongidname=0
				xingzhengfawenNeirong.setZhusong(zhusongname);
			}
		}else{//zhusongname=0
			if(txzhusongidname!=null&&txzhusongidname.length()!=0){
				if(a==true){
					if(aa==true){
						zhusong=txzhusongidname.substring(0, (txzhusongidname.length()-1));
					}else{
						zhusong=txzhusongidname;
					}
					xingzhengfawenNeirong.setZhusong(zhusong);
				}else{
					zhusong=txzhusongidname;
					xingzhengfawenNeirong.setZhusong(zhusong);
				}
			}
		}
	    
	    xingzhengfawenNeirong.setState(1);		
		xingzhengfawenNeirong.setDocname(arg2.getParameter("docname"));
		xingzhengfawenNeirong.setZhuangta("1");
		//添加附件
		if (arg2.getParameter("fujian") != null && !"".equals(arg2.getParameter("fujian"))) {
			xingzhengfawenNeirong.setFujian(arg2.getParameter("fujian"));
		}else{
			xingzhengfawenNeirong.setFujian("");
		}
		xingzhengfawenNeirong.setFujian(xingzhengfawenNeirong.getFujian().replace("<", "&lt;"));
		xingzhengfawenNeirong.setFujian(xingzhengfawenNeirong.getFujian().replace(">", "&gt;"));
		//添加正文
		if (arg2.getParameter("zhengwen") != null && !"".equals(arg2.getParameter("zhengwen"))) {
			xingzhengfawenNeirong.setChaobao(arg2.getParameter("zhengwen"));
		}else{
			xingzhengfawenNeirong.setChaobao("");
		}
		xingzhengfawenNeirong.setChaobao(xingzhengfawenNeirong.getChaobao().replace("<", "&lt;"));
		xingzhengfawenNeirong.setChaobao(xingzhengfawenNeirong.getChaobao().replace(">", "&gt;"));
		//添加备注
		if (arg2.getParameter("beizhu") != null && !"".equals(arg2.getParameter("beizhu"))) {
			xingzhengfawenNeirong.setMiji(arg2.getParameter("beizhu"));
		}else{
			xingzhengfawenNeirong.setMiji("");
		}
		xingzhengfawenNeirong.setMiji(xingzhengfawenNeirong.getMiji().replace("<", "&lt;"));
		xingzhengfawenNeirong.setMiji(xingzhengfawenNeirong.getMiji().replace(">", "&gt;"));
		//xingzhengfawenNeirong.setZhutici(arg2.getParameter("zhutici"));
		String nigaorenid=arg2.getParameter("nigaorenid");
		if(nigaorenid!=null && !"".equals(nigaorenid)){
			xingzhengfawenNeirong.setNigaorenid(Integer.parseInt(nigaorenid));
			/*List<TSystemUserDepartment> systemUserDepartmentList = systemUserDepartmentBo.selectByUserId(Integer.parseInt(nigaorenid));
			if (systemUserDepartmentList.size() > 0) {
				xingzhengfawenNeirong.setChengbanbumen(systemUserDepartmentList.get(0).getDepartmentName());
			} else {
				xingzhengfawenNeirong.setChengbanbumen("");
			}*/
		}
		xingzhengfawenNeirong.setNigaorenname(arg2.getParameter("nigaorenname"));
		xingzhengfawenNeirong.setChengbanbumen(arg2.getParameter("nigaorenunit"));
				
		String year = arg2.getParameter("year");
		Integer yearnumber = Integer.parseInt(year);
		String wenhaonumber = arg2.getParameter("number");
		Integer wenhao = Integer.parseInt(wenhaonumber);
		String wentypeid = arg2.getParameter("subtype");
		Integer typeid = Integer.parseInt(wentypeid);		
		List<SubTypeInfo> subtypelist=wenTypeBO.selectSubTypeById(typeid);  //根据文件类型名查找文件类型对象		
		if (subtypelist.size()<=0){
			return null;
		}
		SubTypeInfo subtype=subtypelist.get(0);
		xingzhengfawenNeirong.setWentype(subtype.getTypeName());
		xingzhengfawenNeirong.setWenyear(yearnumber);
		xingzhengfawenNeirong.setWenhao(wenhao);
		xingzhengfawenNeirong.setWenhaonumber(wenhaonumber);
		xingzhengfawenNeirong.setHaotype(arg2.getParameter("haotype"));//subtype.getWenhaotype()
		xingzhengfawenNeirong.setTemptype(subtype.getTempName());		
		//生成最终文号		
		String wenhaotype="";
		if (subtype.getWenhaotype().indexOf("第期")!=-1) {
			wenhaotype="第"+wenhao.toString()+"期";
		}else{
			wenhaotype= arg2.getParameter("haotype") + "〔" +year+"〕" +wenhaonumber+"号";
		}
		xingzhengfawenNeirong.setWenhaotype(wenhaotype);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String fawenDate=arg2.getParameter("fawenDate");
		java.util.Date fawendate=sdf.parse(fawenDate);
		xingzhengfawenNeirong.setFawendatetime(fawendate);
		xingzhengfawenNeirong.setFengfadate(arg2.getParameter("fengfadate"));

		String hegaorenid = arg2.getParameter("hegaorenid");
		//伪代码
		long startTime=System.currentTimeMillis();   //获取开始时间
		String docid = xingzhengfawenNeirongBO.addqfTXingzhengfawenneirong(xingzhengfawenNeirong,
				arg2.getParameter("bumenhuiqianidname"),arg2.getParameter("zhusongid"), arg2.getParameter("chaosongname"),fileList);
		for (Files files : fileList) {
			ToolKit.copyFile(files.toFilePath, arg2.getSession().getServletContext().getRealPath("/") + "\\"+ "documentationflow\\xingzhengfawen\\docs\\"+files.getNewFileName());
		}
		long endTime=System.currentTimeMillis(); //获取结束时间
		Logger logger = Logger.getLogger(ShenPiAction.class);
		logger.log(Level.ERROR, "添加发文内容时间" + Long.valueOf(endTime-startTime));
		//addJingShouRen(arg2,xingzhengfawenNeirong.getId());			
		endTime=System.currentTimeMillis(); //获取结束时间
		logger.log(Level.ERROR, "总时间" + Long.valueOf(endTime-startTime));
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");		
		arg2.setAttribute("flowid", xingzhengfawenNeirong.getId());
		addksXingzhengfawenyijianks(arg2,"开始"); 
		addbmXingzhengfawenyijianks(arg2,"部门审核");
		addbgsXingzhengfawenyijianks(arg2,"办公室主任复核");
		String huiqianidname=arg2.getParameter("huiqianidname");
		if(huiqianidname!=null && !"".equals(huiqianidname)){
			addfgXingzhengfawenyijianks(arg2,"分管领导审阅");
		}
		String bumenhuiqianidname=arg2.getParameter("bumenhuiqianidname");
		if(bumenhuiqianidname!=null && !"".equals(bumenhuiqianidname)){
			addhqXingzhengfawenyijianks(arg2,"部门主管会签");
		}
		String qianfaidname=arg2.getParameter("qianfaidname");
		if(qianfaidname!=null && !"".equals(qianfaidname)){
			addqfXingzhengfawenyijianks(arg2,"签发");
		}
		 
		//向发文登记簿增加记录
		TXingzhengfawendengjibu xingzhengfawendengjibu = new TXingzhengfawendengjibu();
		xingzhengfawendengjibu.setBumen(xingzhengfawenNeirong.getChengbanbumen());
		xingzhengfawendengjibu.setFawenhao(wenhaotype);
		xingzhengfawendengjibu.setFawenriqi(xingzhengfawenNeirong.getFawendatetime());
		xingzhengfawendengjibu.setZaiyao(xingzhengfawenNeirong.getBiaoti());
		xingzhengfawendengjibu.setDocid(xingzhengfawenNeirong.getId());
		xingzhengfawendengjibuBO.addTxingzhengfawendangjibu(xingzhengfawendengjibu);
		
		return arg0.findForward("success");
	}

	private TXingzhengfawenNeirong addqfXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		//xingzhengfawenYijian.setExamineDate(new Date());
		String qianfa = arg2.getParameter("qianfaid");
		if(qianfa!=null && !"".equals(qianfa)){
			Integer qianfaid = Integer.parseInt(qianfa);
			xingzhengfawenYijian.setExamineUserId(qianfaid);
		}
		xingzhengfawenYijian.setExamineUserName(arg2.getParameter("qianfaidname"));
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}

	private TXingzhengfawenNeirong addhqXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		//xingzhengfawenYijian.setExamineDate(new Date());
		String bumenhuiqian = arg2.getParameter("bumenhuiqianid");
		if(bumenhuiqian!=null && !"".equals(bumenhuiqian)){
			Integer bumenhuiqianid = Integer.parseInt(bumenhuiqian);
			xingzhengfawenYijian.setExamineUserId(bumenhuiqianid);
		}
		xingzhengfawenYijian.setExamineUserName(arg2.getParameter("bumenhuiqianidname"));
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}

	private TXingzhengfawenNeirong addfgXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		//xingzhengfawenYijian.setExamineDate(new Date());
		String huiqianid = arg2.getParameter("huiqianid");
		String huiqianname = arg2.getParameter("huiqianidname");
		//String[] huiqianidarray=huiqianid.split(",");
		boolean a=huiqianname.contains(",");
		boolean b=huiqianname.contains("、");
		if(a==true){
			String[] huiqiannamearray=huiqianname.split(",");
			for (int i = 0; i < huiqiannamearray.length; i++) {
				xingzhengfawenYijian.setExamineUserName(huiqiannamearray[i]);
				xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
				xingzhengfawenYijian.setFlowName(huanjie);
				
				String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
				xingzhengfawenYijian.setFuben(fubenname);
				xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
				xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
			}		
		}
		if(b==true){
			String[] huiqiannamearray=huiqianname.split("、");
			for (int i = 0; i < huiqiannamearray.length; i++) {
				xingzhengfawenYijian.setExamineUserName(huiqiannamearray[i]);
				xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
				xingzhengfawenYijian.setFlowName(huanjie);
				
				String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
				xingzhengfawenYijian.setFuben(fubenname);
				xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
				xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
			}	
		}
		else{
				xingzhengfawenYijian.setExamineUserName(huiqianname);
				xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
				xingzhengfawenYijian.setFlowName(huanjie);
				
				String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
				xingzhengfawenYijian.setFuben(fubenname);
				xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
				xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 		
		}
		return xingzhengfawenNeirong;
	}

	private TXingzhengfawenNeirong addbgsXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		//xingzhengfawenYijian.setExamineDate(new Date());
		//xingzhengfawenYijian.setExamineUserId(225);
		//xingzhengfawenYijian.setExamineUserName("赵世元");
		String fuheren = arg2.getParameter("fuherenid");
		if(fuheren!=null && !"".equals(fuheren)){
			Integer fuherenid = Integer.parseInt(fuheren);
			xingzhengfawenYijian.setExamineUserId(fuherenid);
		}
		xingzhengfawenYijian.setExamineUserName(arg2.getParameter("fuherenname"));
		xingzhengfawenYijian.setOpinion(arg2.getParameter("fuherenoption"));
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}

	private TXingzhengfawenNeirong addbmXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		//xingzhengfawenYijian.setExamineDate(new Date());
		String hegaoren = arg2.getParameter("hegaorenid");
		if(hegaoren!=null && !"".equals(hegaoren)){
			Integer hegaorenid = Integer.parseInt(hegaoren);
			xingzhengfawenYijian.setExamineUserId(hegaorenid);
		}
		xingzhengfawenYijian.setExamineUserName(arg2.getParameter("hegaorenname"));
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}

	/**
	 * 控制
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward kongzhi(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong  xingzhengfawenNeirong =  xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));		
		Long id = Long.valueOf(arg2.getParameter("taskid"));
		arg2.setAttribute("taskid", id);
		TaskInstance taskInstance   = workFlowTemplate.nextStep(id);
		Date date = workFlowTemplate.processInstanceDate(taskInstance.getProcessInstance().getId());
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
//		arg2.getSession().setAttribute("weijian", xingzhengfawenNeirong);
		if (taskInstance.getDescription().equals("部门审核")) {
			return arg0.findForward("bumenshenhe");
		}
		else if (taskInstance.getDescription().equals("办公室主任复核")) {
			return arg0.findForward("bangongshifuhe");
		}
		else if (taskInstance.getDescription().equals("部门主管会签")) {
			return arg0.findForward("bumenzhuguanhuiqian");
		}
		else if (taskInstance.getDescription().equals("分管领导审阅")) {
			return arg0.findForward("huiqian");
		}
		else if (taskInstance.getDescription().equals("签发")) {
			return arg0.findForward("qianfa");
		}
		else if (taskInstance.getDescription().equals("拟稿人修改内容")) {
			return arg0.findForward("nigaorenxiugaineirong");
		}
		else if (taskInstance.getDescription().equals("拟稿人修改")) {
			return arg0.findForward("nigaorenxiugai");
		}
		else if (taskInstance.getDescription().equals("发文登记")) {
			List<SubTypeInfo> subTypeList = wenTypeBO.selectSubType(1); //查询所有行政发文的文种
			arg2.setAttribute("subtypelist", subTypeList);
			return arg0.findForward("fawendengji");
		}
		else if (taskInstance.getDescription().equals("校对套红")) {
			List<LianDong> zhuSonglist =  lianDongBO.selectAllLianDong();
			arg2.setAttribute("zhusong", zhuSonglist);
			arg2.getSession().setAttribute("taohongtype", "行政发文");
			TaoHongMoBan taoHongMoBan = new TaoHongMoBan();
			taoHongMoBan.setState(xingzhengfawenNeirong.getState());
			taoHongMoBan.setFlowType("xingzhengfawen");
			List<TaoHongMoBan>  taoHongMoBanList =   xingzhengfawenNeirongBO.selectTaoHongMoBan(taoHongMoBan);			
			arg2.getSession().setAttribute("taoHongMoBanList", taoHongMoBanList);
		//	arg2.getSession().setAttribute("doc", xingzhengfawenNeirong);
			return arg0.findForward("taohong");
		}
		else if (taskInstance.getDescription().equals("盖章")) {
			YinZhang yinZhang = new YinZhang();
			yinZhang.setState(xingzhengfawenNeirong.getState());
			yinZhang.setFlowType("xingzhengfawen");
			List<YinZhang>  yinZhangList =   xingzhengfawenNeirongBO.selectYinZhang(yinZhang);
			arg2.getSession().setAttribute("yinZhangList", yinZhangList);
		//	arg2.getSession().setAttribute("doc", xingzhengfawenNeirong);
			
			String gaizhangtype=(String)workFlowTemplate.getVariable("盖章类型", xingzhengfawenNeirong.getFlowid().longValue());
			arg2.setAttribute("gaizhangtype", gaizhangtype);
			return arg0.findForward("gaizhang");
		}
		else if (taskInstance.getDescription().equals("套红修改")) {
			arg2.getSession().setAttribute("taohongtype", "行政发文");
			TaoHongMoBan taoHongMoBan = new TaoHongMoBan();
			taoHongMoBan.setState(xingzhengfawenNeirong.getState());
			taoHongMoBan.setFlowType("xingzhengfawen");
			List<TaoHongMoBan>  taoHongMoBanList =   xingzhengfawenNeirongBO.selectTaoHongMoBan(taoHongMoBan);			
			arg2.getSession().setAttribute("taoHongMoBanList", taoHongMoBanList);
			arg2.getSession().setAttribute("doc", xingzhengfawenNeirong);
			return arg0.findForward("taohongxiugai");
		}
		else if (taskInstance.getDescription().equals("封发")) {
			addXingzhengfawenyijian(arg2,"封发");
			workFlowTemplate.nextStep(Long.valueOf(id), null); 
			if(arg2.getParameter("zhuangta").equals("1")){
				return arg0.findForward("fengfaselectonedoc");
			}else{
				return arg0.findForward("fengfa");
			}
			
			
		}
		return arg0.findForward("success");
	}
	
	/**
	 * 最小年份
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward updateYear(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		 
		String fawenDate = arg2.getParameter("fawenDate");
		fawenDate =  ToolKit.getFormatDate(ToolKit.FormatDate(fawenDate) ,"yyyy年M月d日");
		arg3.getWriter().print(fawenDate);
		return null;
	} 
	/**
	 * 部门审核  核稿
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward bumenshenhe(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"部门审核");
		String taskid = arg2.getParameter("taskid");
		Long flowidL = xingzhengfawenNeirong.getFlowid().longValue();
		workFlowTemplate.setVariable("拟稿人修改内容", xingzhengfawenNeirong.getNigaorenid().toString(), flowidL );
		String bumenhuiqianid = arg2.getParameter("bumenhuiqianid");
		String fuherenid =  arg2.getParameter("fuherenid");
		if ("1".equals(arg2.getParameter("path"))) {  //审核通过
			if(fuherenid != null && !"".equals(fuherenid)){  //需要本部门其他负责人审核
				workFlowTemplate.setVariable("部门审核", fuherenid,flowidL );
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 部门审核");
			}else if (bumenhuiqianid != null && !"".equals(bumenhuiqianid)){		//不需要本部门其他负责人审核，需要会签
				List<String> bmhuiqianlist = new ArrayList<String>();
				String[] bmhuiqianarray = arg2.getParameter("bumenhuiqianid").split(",");
				if(bmhuiqianarray.length>1){
					for (int i = 1; i < bmhuiqianarray.length; i++) {
						if (bmhuiqianarray[i] !=null &&!"".equals(bmhuiqianarray[i])) {
							bmhuiqianlist.add(bmhuiqianarray[i]);
						}
					}
					workFlowTemplate.setVariable("部门会签顺序组", bmhuiqianlist,flowidL );
				}else{
					workFlowTemplate.setVariable("部门会签顺序组", null,flowidL );
				}
				workFlowTemplate.setVariable("部门主管会签", bmhuiqianarray[0],flowidL );
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 部门主管会签");
			}else{		//不需要会签，转到办公室主任复核环节
				List<TSystemUser> systemuserlist = null;
				systemuserlist = systemUserBo.selectByDutyName("办公室主任");
				if (systemuserlist.size() > 0) {
					TSystemUser systemUser = systemuserlist.get(0);
					workFlowTemplate.setVariable("办公室主任复核", systemUser.getUserId().toString(),flowidL );
				} else {
					workFlowTemplate.setVariable("办公室主任复核", "1", flowidL );
				}
				workFlowTemplate.nextStep(Long.valueOf(taskid), "to 办公室主任复核");	
			}
		} else {
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 拟稿人修改内容");
		}
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 办公室主任复核	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward bangongshifuhe(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"办公室主任复核");
		String taskid = arg2.getParameter("taskid");
		Long flowidL = xingzhengfawenNeirong.getFlowid().longValue();
		String huiqianidStr=arg2.getParameter("huiqianid");
		if ("1".equals(arg2.getParameter("path"))){ //判断是否通过
			if (huiqianidStr != null &&!"".equals(huiqianidStr)) { //可以会签
				List<String> huiqianlist = new ArrayList<String>();
				String[] huiqianarray = huiqianidStr.split(",");
				if(huiqianarray.length>1){
					for (int i = 1; i < huiqianarray.length; i++) {
						if (huiqianarray[i] !=null &&!"".equals(huiqianarray[i])) {
							huiqianlist.add(huiqianarray[i]);
						}
					}
					workFlowTemplate.setVariable("分管领导审阅顺序组", huiqianlist,flowidL );
				}else{
					workFlowTemplate.setVariable("分管领导审阅顺序组", null,flowidL );
				}
				if (huiqianarray[0] !=null &&!"".equals(huiqianarray[0])) {
					workFlowTemplate.setVariable("分管领导审阅", huiqianarray[0],flowidL );
					workFlowTemplate.setVariable("签发", arg2.getParameter("qianfaid"),flowidL );
					workFlowTemplate.nextStep(Long.valueOf(taskid),"to 分管领导审阅");
				}else{
					workFlowTemplate.setVariable("签发", arg2.getParameter("qianfaid"),flowidL );
					workFlowTemplate.nextStep(Long.valueOf(taskid),"to 签发");
				}
			} else {  //签发
				workFlowTemplate.setVariable("签发", arg2.getParameter("qianfaid"),flowidL );
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 签发");
			}
		}else {
			tuihuinigaoren(Long.valueOf(xingzhengfawenNeirong.getFlowid()),Long.valueOf(taskid));
		}
		
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 部门主管会签
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward bumenzhuguanhuiqian(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"部门主管会签");
		String taskid = arg2.getParameter("taskid");
		Long flowidL = xingzhengfawenNeirong.getFlowid().longValue();
		if ("1".equals(arg2.getParameter("path"))) {
			Object bmhuiqianzu=workFlowTemplate.getVariable("部门会签顺序组", flowidL);
			if(bmhuiqianzu!=null){
				List<String> bmhuiqianlist = (List<String>)bmhuiqianzu;
				String bmhuiqianid=bmhuiqianlist.get(0);
				if(!"".equals(bmhuiqianid)&&bmhuiqianid!=null){
					workFlowTemplate.setVariable("部门主管会签",bmhuiqianid ,flowidL);
				}else{
					workFlowTemplate.setVariable("部门主管会签",1 ,flowidL);
				}
				if(bmhuiqianlist.size()>1){
					List<String> newlist = new ArrayList<String>();
					for (int i = 1; i < bmhuiqianlist.size(); i++) {
						newlist.add(bmhuiqianlist.get(i));
					}
					workFlowTemplate.setVariable("部门会签顺序组",newlist ,flowidL);
				}else{
					workFlowTemplate.setVariable("部门会签顺序组",null ,flowidL);
				}
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 部门主管会签");
			}else{    //会签顺序组内已无待会签用户
				List<TSystemUser> systemuserlist = null;
				systemuserlist = systemUserBo.selectByDutyName("办公室主任");
				if (systemuserlist.size() > 0) {
					TSystemUser systemUser = systemuserlist.get(0);
					workFlowTemplate.setVariable("办公室主任复核", systemUser.getUserId().toString(), flowidL );
				} else {
					workFlowTemplate.setVariable("办公室主任复核", "1",flowidL);
				}
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 办公室主任复核");
			}
		} else {
			tuihuinigaoren(flowidL,Long.valueOf(taskid));
		}
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 分管领导审阅
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward huiqian(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"分管领导审阅");
		String taskid = arg2.getParameter("taskid");
		Long flowidL = xingzhengfawenNeirong.getFlowid().longValue();
		if ("1".equals(arg2.getParameter("path"))) {
			Object bmhuiqianzu=workFlowTemplate.getVariable("分管领导审阅顺序组", flowidL);
			if(bmhuiqianzu!=null){
				List<String> huiqianlist = (List<String>)bmhuiqianzu;
				String huiqianid=huiqianlist.get(0);
				if(!"".equals(huiqianid)&&huiqianid!=null){
					workFlowTemplate.setVariable("分管领导审阅",huiqianid ,flowidL);
				}else{
					workFlowTemplate.setVariable("分管领导审阅",1 ,flowidL);
				}
				if(huiqianlist.size()>1){
					List<String> newlist = new ArrayList<String>();
					for (int i = 1; i < huiqianlist.size(); i++) {
						newlist.add(huiqianlist.get(i));
					}
					workFlowTemplate.setVariable("分管领导审阅顺序组",newlist ,flowidL);
				}else{
					workFlowTemplate.setVariable("分管领导审阅顺序组",null ,flowidL);
				}
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 分管领导审阅");
			}else{    //会签顺序组内已无待会签用户	
				workFlowTemplate.nextStep(Long.valueOf(taskid),"to 签发");
			}
		} else {
			tuihuinigaoren(Long.valueOf(xingzhengfawenNeirong.getFlowid()),Long.valueOf(taskid));
		}
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 签发
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward qianfa(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"签发");
		
		String taskid = arg2.getParameter("taskid");
		if ("1".equals(arg2.getParameter("path"))) {
			
			List<TSystemUser> systemuserlist = null;
			systemuserlist = systemUserBo.selectByPostName("行政发文登记人");
			if (systemuserlist.size() > 0) {
				TSystemUser systemUser = systemuserlist.get(0);
				workFlowTemplate.setVariable("发文登记", systemUser.getUserId().toString(),Long.valueOf(arg2.getParameter("flowid")) );
			} else {
				workFlowTemplate.setVariable("发文登记", "1",Long.valueOf(arg2.getParameter("flowid")) );
			}
			if(arg2.getParameter("qianfaid") != null &&!"".equals(arg2.getParameter("qianfaid")))
			{
				workFlowTemplate.createTaskInstance(Long.valueOf(taskid), arg2.getParameter("qianfaid"));
			}else{
				xingzhengfawenNeirong.setFawendatetime(new Date());
				xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
			}
			workFlowTemplate.nextStep(Long.valueOf(taskid),"to 发文登记");
		} else {
			tuihuinigaoren(Long.valueOf(xingzhengfawenNeirong.getFlowid()),Long.valueOf(taskid));
		}
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	

	/**
	 * 拟稿人修改内容	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward nigaorenxiugaineirong(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		addXingzhengfawenyijian(arg2,"拟稿人修改内容");
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String taskid = arg2.getParameter("taskid");
		if(workFlowTemplate.getVariable("部门审核", Long.valueOf(arg2.getParameter("flowid")))!=null){
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 部门审核");
		}else {
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 办公室主任复核");
		}
		
		/*arg2.setAttribute("linkurl", "/documentationflow/xingzhengfawen/daibanlist.jsp?state="+ xingzhengfawenNeirong.getState());
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");*/
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 发文登记
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward fawendengji(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		String taskid = arg2.getParameter("taskid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"发文登记");
//		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		//判断是否退回
		if ("0".equals(arg2.getParameter("path"))) {  
			//退回处理
			tuihuinigaoren(Long.valueOf(xingzhengfawenNeirong.getFlowid()),Long.valueOf(taskid));
		}else{
			WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
			//通过处理
			String fawendate = arg2.getParameter("fawenDate");
			String year = arg2.getParameter("year");
			Integer yearnumber = Integer.parseInt(year);
			String wenhaonumber = arg2.getParameter("number");
			Integer wenhao = Integer.parseInt(wenhaonumber);
			String wentypeid = arg2.getParameter("subtype");
			Integer typeid = Integer.parseInt(wentypeid);
			
			List<SubTypeInfo> subtypelist=wenTypeBO.selectSubTypeById(typeid);  //根据文件类型名查找文件类型对象
			
			if (subtypelist.size()<=0){
				return null;
			}
			SubTypeInfo subtype=subtypelist.get(0);
			xingzhengfawenNeirong.setWentype(subtype.getTypeName());
			xingzhengfawenNeirong.setWenyear(yearnumber);
			xingzhengfawenNeirong.setWenhao(wenhao);
			xingzhengfawenNeirong.setWenhaonumber(wenhaonumber);
			xingzhengfawenNeirong.setHaotype(subtype.getWenhaotype());
			xingzhengfawenNeirong.setTemptype(subtype.getTempName());
			
			//生成最终文号
			
			String wenhaotype="";
			if (subtype.getWenhaotype().indexOf("第期")!=-1) {
				wenhaotype="第"+wenhao.toString()+"期";
			}else{
				wenhaotype= subtype.getWenhaotype() + "〔" +year+"〕" +wenhaonumber+"号";
			}
			xingzhengfawenNeirong.setWenhaotype(wenhaotype);
			xingzhengfawenNeirong.setFenshu(arg2.getParameter("fenshu"));
			xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
			
			workFlowTemplate.setVariable("校对套红", xingzhengfawenNeirong.getNigaorenid().toString(), 
					Long.parseLong(xingzhengfawenNeirong.getFlowid().toString()) );
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 校对套红");
			
			//向发文登记簿增加记录
			TXingzhengfawendengjibu xingzhengfawendengjibu = new TXingzhengfawendengjibu();
			xingzhengfawendengjibu.setBumen(xingzhengfawenNeirong.getChengbanbumen());
			xingzhengfawendengjibu.setFawenhao(wenhaotype);
			xingzhengfawendengjibu.setFawenriqi(xingzhengfawenNeirong.getFawendatetime());
			xingzhengfawendengjibu.setZaiyao(xingzhengfawenNeirong.getBiaoti());
			xingzhengfawendengjibu.setDocid(arg2.getParameter("id"));
			xingzhengfawendengjibuBO.addTxingzhengfawendangjibu(xingzhengfawendengjibu);
			
		}
		//添加经手人
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		//跳转返回发文管理页面
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 校对套红
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward jiaoduitaohong(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		TXingzhengfawenNeirong xingzhengfawenNeirong = addXingzhengfawenyijian(arg2,"校对套红");
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String taskid = arg2.getParameter("taskid");
		addJingShouRen(arg2,arg2.getParameter("id"));
		Long flowidL = Long.valueOf(arg2.getParameter("flowid")) ;
		String gaizhangtype=arg2.getParameter("path");  //盖章类型，0:不盖章 1:行政盖章 2:联合盖章
		if ("0".equals(gaizhangtype)) {  
			String fengfadate = ToolKit.FormatDate(new Date(), "yyyy年MM月dd日");
			xingzhengfawenNeirong.setFengfadate(fengfadate);
			xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 封发");
		}else{
			List<TSystemUser> systemuserlist = null;
			systemuserlist = systemUserBo.selectByPostName("行政盖章人");
			if (systemuserlist.size() > 0) {
				TSystemUser systemUser = systemuserlist.get(0);
				workFlowTemplate.setVariable("盖章", systemUser.getUserId().toString(),flowidL);
				if("1".equals(gaizhangtype)){
					workFlowTemplate.setVariable("盖章类型", "行政盖章", flowidL );
				}else{
					workFlowTemplate.setVariable("盖章类型", "党政联合盖章", flowidL );
				}
			}
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 盖章");
		}
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	
	/**
	 * 套红修改
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward taohongxiugai(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
	//	TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		addXingzhengfawenyijian(arg2,"套红修改");
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String taskid = arg2.getParameter("taskid");
		workFlowTemplate.nextStep(Long.valueOf(taskid), null);
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 盖章
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	
	public ActionForward gaiZhang(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String taskid = arg2.getParameter("taskid");
		addJingShouRen(arg2,xingzhengfawenNeirong.getId());
		if ("1".equals(arg2.getParameter("path"))) {
			String fengfadate = ToolKit.FormatDate(new Date(), "yyyy年MM月dd日");
			xingzhengfawenNeirong.setFengfadate(fengfadate);
			xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 封发");
		} else {
			workFlowTemplate.nextStep(Long.valueOf(taskid), "to 套红修改");
		}
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	private void tuihuinigaoren(Long flowid, Long taskid ){
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Collection<TaskInstance> collectiontask = workFlowTemplate.selectunfinishedTasks(flowid);
		for (TaskInstance taskInstance : collectiontask) {
			if(taskInstance.getId() != taskid)
			{
				xingzhengfawenNeirongBO.deleteTask(Integer.parseInt(Long.valueOf(taskInstance.getId()).toString())  );
			}
		}
		workFlowTemplate.nextStep(taskid, "to 拟稿人修改内容");
	}
	
	
	/**
	 * 重新修改
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward chongxinxiugai(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String flowid = arg2.getParameter("id");
		workFlowTemplate.signal(Long.valueOf(flowid)); 
		arg2.setAttribute("linkurl", "documentationflow/xingzhengfawen/xingzhengflowgenzong.jsp");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 添加意见
	 * @param arg2
	 * @param 环节
	 * @return
	 */
	private TXingzhengfawenNeirong addXingzhengfawenyijian(HttpServletRequest arg2,String huanjie) {
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		xingzhengfawenYijian.setExamineDate(new Date());
		xingzhengfawenYijian.setExamineUserId(SessionUser.getUserId(arg2));
		xingzhengfawenYijian.setExamineUserName(SessionUser.getUser(arg2).getUsername());
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		if(arg2.getParameter("yijian") !=null ){
			xingzhengfawenYijian.setOpinion(arg2.getParameter("yijian"));
		}else{
			xingzhengfawenYijian.setOpinion("");
		}
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}
	
	/**
	 * 添加意见
	 * @param arg2
	 * @param 开始环节
	 * @return
	 */
	private TXingzhengfawenNeirong addXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		xingzhengfawenYijian.setExamineDate(new Date());
		xingzhengfawenYijian.setExamineUserId(SessionUser.getUserId(arg2));
		xingzhengfawenYijian.setExamineUserName(SessionUser.getUser(arg2).getUsername());
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		if(arg2.getParameter("yijian") !=null ){
			xingzhengfawenYijian.setOpinion(arg2.getParameter("yijian"));
		}else{
			xingzhengfawenYijian.setOpinion("");
		}
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}
	
	private TXingzhengfawenNeirong addksXingzhengfawenyijianks(HttpServletRequest arg2,String huanjie) {
		String flowid = (String) arg2.getAttribute("flowid");
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(flowid);
		TXingzhengfawenYijian xingzhengfawenYijian = new TXingzhengfawenYijian();
		xingzhengfawenYijian.setExamineDate(new Date());
		xingzhengfawenYijian.setExamineUserId(xingzhengfawenNeirong.getNigaorenid());
		xingzhengfawenYijian.setExamineUserName(xingzhengfawenNeirong.getNigaorenname());
		xingzhengfawenYijian.setFlowId(xingzhengfawenNeirong.getFlowid());
		xingzhengfawenYijian.setFlowName(huanjie);
		if(arg2.getParameter("yijian") !=null ){
			xingzhengfawenYijian.setOpinion(arg2.getParameter("yijian"));
		}else{
			xingzhengfawenYijian.setOpinion("");
		}
		
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		xingzhengfawenYijian.setFuben(fubenname);
		xingzhengfawenYijian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
		xingzhengfawenYijianBO.addXingzhengfawenyijian(xingzhengfawenYijian); 
		return xingzhengfawenNeirong;
	}
	private String addFuben(String docname){
		String rodomerstr = ToolKit.getRodomer();
			
			try { 
				 String path =  super.getServlet().getServletContext().getRealPath("/");
				  FileInputStream   fis   =   new   FileInputStream(path+"documentationflow\\xingzhengfawen\\docs\\"+docname);   
			          FileOutputStream   fos   =   new   FileOutputStream(path+"documentationflow\\xingzhengfawen\\fuben\\" + rodomerstr+".doc");   
			          byte[]   buf   =   new   byte[1024];   
			          int   i   =   0;   
			          while   (   (i   =   fis.read(buf))   !=   -1)   {   
			              fos.write(buf,   0,   i);   
			          }   
			          fis.close();   
			          fos.close();
			          return rodomerstr+".doc";
			     }  
			     catch  (Exception  e)  {  
			         e.printStackTrace();  
			         return "";
			     }
		}
	
	/**
	 * 副本列表
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward fubenlist(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		Integer first = 0;
		String path = arg2.getContextPath();
		String basePath = arg2.getScheme()+"://"+arg2.getServerName()+":"+arg2.getServerPort()+path+"/";
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		List<TXingzhengfawenYijian > list  = null;
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TXingzhengfawenYijian.class);
		detachedCriteria.add(Restrictions.eq("xingzhengfawenNeirong.id", arg2.getParameter("id")));
		if (arg2.getParameter("start") == null) {
			list = xingzhengfawenYijianBO.selectFuBenPage(detachedCriteria, 0);
		} else {
			 first = Integer.parseInt(arg2.getParameter("start"));
			list = xingzhengfawenYijianBO.selectFuBenPage(detachedCriteria, first);
		}
		Integer totalProperty = xingzhengfawenYijianBO.selectFuBenTotalLine(detachedCriteria);
		object.put("totalProperty", totalProperty);
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			TXingzhengfawenYijian xingzhengfawenYijian = (TXingzhengfawenYijian) iterator.next();
			JSONObject taskObject = new JSONObject();
			taskObject.put("username", xingzhengfawenYijian.getExamineUserName());
			taskObject.put("flowname", xingzhengfawenYijian.getFlowName());
			taskObject.put("time", ToolKit.getFormatDate(xingzhengfawenYijian.getExamineDate(), "yyyy-MM-dd HH:mm"));
			if(xingzhengfawenYijian.getFlowName().equals("修改正文")){
				taskObject.put("operate", "<a href='"+basePath+"documentationflow/xingzhengfawen/openfuben2.jsp?docname="+xingzhengfawenYijian.getFuben()+
					"&id="+arg2.getParameter("id")+"'>查看</a>"+ 
					"&nbsp;&nbsp;<a href='"+basePath+"documentationflow/xingzhengfawen/fuben/"+ xingzhengfawenYijian.getFuben()+"'>下载</a>");
				array.put(taskObject);
			}else{
				taskObject.put("operate", "<a href='"+basePath+"documentationflow/xingzhengfawen/openfuben.jsp?docname="+xingzhengfawenYijian.getFuben()+
						"&id="+arg2.getParameter("id")+"'>查看</a>"+ 
						"&nbsp;&nbsp;<a href='"+basePath+"documentationflow/xingzhengfawen/fuben/"+ xingzhengfawenYijian.getFuben()+"'>下载</a>");
				array.put(taskObject);
			}			
		}
		arg2.getSession().setAttribute("xingzhengfafubenliststart", first);
		object.put("root", array);
		arg3.getWriter().print(object);
		return null;
	}
	/**
	 * 跟踪
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward genzong(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long flowid = Long.valueOf(arg2.getParameter("flowid"));
		Integer unfinshtasksize  = workFlowTemplate.selectunfinishedTasksSize(flowid);
		PaginationSupport paginationSupport = null;
		List<Taskinstance> list;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (arg2.getParameter("start") == null) {
			paginationSupport =  taskInstanceBO.genZong(flowid, 0, 23);
		} else {
			Integer first = Integer.parseInt(arg2.getParameter("start"));
			paginationSupport = taskInstanceBO.genZong(flowid, first, 23);
		}
		Integer totalProperty = paginationSupport.getTotalCount();
		object.put("totalProperty", totalProperty);
		list = paginationSupport.getItems();
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			Taskinstance taskinstance = (Taskinstance)iterator.next();
			JSONObject taskObject = new JSONObject();
			taskObject.put("taskname", taskinstance.getName());
			taskObject.put("username", taskinstance.getTjsUser().getUserName());
			taskObject.put("time", ToolKit.getFormatDate(taskinstance.getEnd(), "yyyy-MM-dd HH:mm"));
			if(taskinstance.getEnd() ==null&& unfinshtasksize > 1)
			{
				taskObject.put("operate", "<a href='javascript:changActorByUserId("+taskinstance.getId()+",\""+taskinstance.getName()+"\")'>修改候选人</a>&nbsp;&nbsp;<a href='javascript:endTask("+taskinstance.getId()+")'>结束</a>");
			}
			else if(taskinstance.getEnd() ==null)
			{
				taskObject.put("operate", "<a href='javascript:javascript:changActorByUserId("+taskinstance.getId()+",\""+taskinstance.getName()+"\")'>修改候选人</a>");
			}
			else
			{
				taskObject.put("operate", "");
			}
			array.put(taskObject);
		}
		object.put("root", array);
		arg3.getWriter().print(object);
		return null;
	}
	
	/**
	 * 下载附件
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward download(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		String url = "error";
		InputStream fis =  null;
		OutputStream toClient =  null;
		// TODO Auto-generated method stub
		try {
			String id=arg2.getParameter("id");
			TXingzhengfawenFujian	 xingzhengfawenFujian = xingzhengfawenFujianBO.selectById(id );
			String desfile = xingzhengfawenFujian.getFujianAddress().substring(0,xingzhengfawenFujian.getFujianAddress().lastIndexOf("\\")) +"\\"+ xingzhengfawenFujian.getFujianName();
			desfile = ToolKit.delHTMLTag(desfile);
			ToolKit.copyFile(xingzhengfawenFujian.getFujianAddress(),desfile); 
			File file = new File(desfile); 			
			String filename = file.getName();
			 fis = new BufferedInputStream(new FileInputStream(desfile));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();		
			arg3.reset();
			arg3.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"iso8859-1"));
			//arg3.addHeader("Content-Disposition ",   "attachment;filename="+ new String(xingzhengfawenFujian.getFujianName().getBytes(),"GBK"));
			arg3.addHeader("Content-Length", "" + file.length());
	         toClient = new BufferedOutputStream(arg3.getOutputStream());
	        arg3.setContentType("application/octet-stream");
	        toClient.write(buffer);
	        toClient.flush();
	        toClient.close();
			url = "ok";
		} catch (IOException ex) {
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			ex.printStackTrace();
			return arg0.findForward("error");
		} catch(NullPointerException ex){
			return null;
		} catch (Exception ex){
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			return arg0.findForward("error");
		}finally{
			fis.close();
			 toClient.close();
		}
		if ("ok".equals(url)) {
			return null;	
		}else {
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			return  arg0.findForward(url);
		}
	}
	/*
	 * 下载正文
	 */
	public ActionForward downloadzw(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		String url = "error";
		InputStream fis =  null;
		OutputStream toClient =  null;
		// TODO Auto-generated method stub
		try {
			String id=arg2.getParameter("id");
			TXingzhengfawenZhengwen	xingzhengfawenZhengwen = xingzhengfawenZhengwenBO.selectById(id);
			String desfile = xingzhengfawenZhengwen.getzhengwenAddress().substring(0,xingzhengfawenZhengwen.getzhengwenAddress().lastIndexOf("\\")) +"\\"+ xingzhengfawenZhengwen.getzhengwenName();
			desfile = ToolKit.delHTMLTag(desfile);
			ToolKit.copyFile(xingzhengfawenZhengwen.getzhengwenAddress(),desfile); 
			File file = new File(desfile); 			
			String filename = file.getName();
			 fis = new BufferedInputStream(new FileInputStream(desfile));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();		
			arg3.reset();
			arg3.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"iso8859-1"));
			//arg3.addHeader("Content-Disposition ",   "attachment;filename="+ new String(xingzhengfawenFujian.getFujianName().getBytes(),"GBK"));
			arg3.addHeader("Content-Length", "" + file.length());
	         toClient = new BufferedOutputStream(arg3.getOutputStream());
	        arg3.setContentType("application/octet-stream");
	        toClient.write(buffer);
	        toClient.flush();
	        toClient.close();
			url = "ok";
		} catch (IOException ex) {
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			ex.printStackTrace();
			return arg0.findForward("error");
		} catch(NullPointerException ex){
			return null;
		} catch (Exception ex){
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			return arg0.findForward("error");
		}finally{
			fis.close();
			 toClient.close();
		}
		if ("ok".equals(url)) {
			return null;	
		}else {
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			return  arg0.findForward(url);
		}
	}
	/*
	 * 下载备注
	 */
	public ActionForward downloadbz(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		String url = "error";
		InputStream fis =  null;
		OutputStream toClient =  null;
		// TODO Auto-generated method stub
		try {
			String id=arg2.getParameter("id");
			TXingzhengfawenBeizhu xingzhengfawenBeizhu = xingzhengfawenBeizhuBO.selectById(id);
			String desfile = xingzhengfawenBeizhu.getbeizhuAddress().substring(0,xingzhengfawenBeizhu.getbeizhuAddress().lastIndexOf("\\")) +"\\"+ xingzhengfawenBeizhu.getbeizhuName();
			desfile = ToolKit.delHTMLTag(desfile);
			ToolKit.copyFile(xingzhengfawenBeizhu.getbeizhuAddress(),desfile); 
			File file = new File(desfile); 			
			String filename = file.getName();
			 fis = new BufferedInputStream(new FileInputStream(desfile));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();		
			arg3.reset();
			arg3.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"iso8859-1"));
			//arg3.addHeader("Content-Disposition ",   "attachment;filename="+ new String(xingzhengfawenFujian.getFujianName().getBytes(),"GBK"));
			arg3.addHeader("Content-Length", "" + file.length());
	         toClient = new BufferedOutputStream(arg3.getOutputStream());
	        arg3.setContentType("application/octet-stream");
	        toClient.write(buffer);
	        toClient.flush();
	        toClient.close();
			url = "ok";
		} catch (IOException ex) {
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			ex.printStackTrace();
			return arg0.findForward("error");
		} catch(NullPointerException ex){
			return null;
		} catch (Exception ex){
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			return arg0.findForward("error");
		}finally{
			fis.close();
			 toClient.close();
		}
		if ("ok".equals(url)) {
			return null;	
		}else {
			arg2.setAttribute("returnSting", "服务器忙，请稍后下载！");
			return  arg0.findForward(url);
		}
	}
	/**
	 * 中止一个流程

	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward suspend(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long flowid = Long.valueOf(arg2.getParameter("flowid"));
		   if (workFlowTemplate.processInstanceSuspend(flowid)) {
		    	JSONObject object = new JSONObject();
		    	object.put("success", true);
		    	arg3.getWriter().print(object);
			} else {
				JSONObject object = new JSONObject();
		    	object.put("success", false);
		    	arg3.getWriter().print(object);
			}
		return null;
	}
	
	
	/**
	 * 完结一个流程

	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward end(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long flowid = Long.valueOf(arg2.getParameter("flowid"));
		   if (workFlowTemplate.processInstanceEnd(flowid)) {
			    List<TaskInstance> list = new ArrayList<TaskInstance>(workFlowTemplate.selectunfinishedTasks(flowid));
			    for (TaskInstance taskInstance : list) {
					xingzhengfawenNeirongBO.deleteTask(Integer.parseInt(Long.valueOf(taskInstance.getId()).toString())  );
				}
		    	JSONObject object = new JSONObject();
		    	object.put("success", true);
		    	arg3.getWriter().print(object);
			} else {
				JSONObject object = new JSONObject();
		    	object.put("success", false);
		    	arg3.getWriter().print(object);
			}
		return null;
	}
	
	/**
	 * 重启一个流程

	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward resume(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long flowid = Long.valueOf(arg2.getParameter("flowid"));
		   if (workFlowTemplate.processInstanceResume(flowid)) {
		    	JSONObject object = new JSONObject();
		    	object.put("success", true);
		    	arg3.getWriter().print(object);
			} else {
				JSONObject object = new JSONObject();
		    	object.put("success", false);
		    	arg3.getWriter().print(object);
			}
		return null;
	}
	
	/**
	 * 改变任务接收人

	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward changActor(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long taskid = Long.valueOf(arg2.getParameter("taskid"));
		String actorid = arg2.getParameter("actorid");
		if (workFlowTemplate.changTaskActor(taskid,actorid)) {
			JSONObject object = new JSONObject();
	    	object.put("success", true);
	    	arg3.getWriter().print(object);
		} else {
			JSONObject object = new JSONObject();
	    	object.put("success", false);
	    	arg3.getWriter().print(object);
		}				 
		return null;
	}
	
	/**
	 * 增加任务接收人


	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward addTask(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long flowId = Long.valueOf(arg2.getParameter("flowid"));
		String actorIds = arg2.getParameter("actorid");
		Collection<TaskInstance> tasks = workFlowTemplate.selectunfinishedTasks(flowId);
	//	Long taskId= (long) 1057;
		if (tasks.isEmpty()){
			JSONObject object = new JSONObject();
	    	object.put("success", false);
	    	arg3.getWriter().print(object);
			return null;		
		}
		TaskInstance taskInstance =  (TaskInstance) workFlowTemplate.selectunfinishedTasks(flowId).toArray()[0];
		
		Boolean flagadd=false;
		if (actorIds!=null && !"".equals(actorIds)){
			String[] actoridsarray = actorIds.split(",");
			flagadd = true;
			for(String actorId : actoridsarray){
				flagadd = flagadd && workFlowTemplate.createTaskInstance(taskInstance.getId(), actorId);
			//	flagadd = flagadd && workFlowTemplate.createTaskInstance(taskId, actorId);
			}
		}
		if (flagadd) {
			JSONObject object = new JSONObject();
	    	object.put("success", true);
	    	arg3.getWriter().print(object);
		} else {
			JSONObject object = new JSONObject();
	    	object.put("success", false);
	    	arg3.getWriter().print(object);
		}				 
		return null;		
	}
	
	/**
	 * 删除任务
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward deleteTask(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		Long taskid = Long.valueOf(arg2.getParameter("taskid"));
		if (xingzhengfawenNeirongBO.deleteTask(Integer.parseInt(taskid.toString())  )) {
			JSONObject object = new JSONObject();
	    	object.put("success", true);
	    	arg3.getWriter().print(object);
		} else {
			JSONObject object = new JSONObject();
	    	object.put("success", false);
	    	arg3.getWriter().print(object);
		}				 
		return null;
	}
	/**
	 * 只读查询发文内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward selectonedoc(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);	
		
		//arg2.setAttribute("xingzhengfawenFujian", xingzhengfawenFujian);		
		
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
//		List<TSystemUserDepartment> systemUserDepartmentList =  null;
//		if(arg2.getParameter("userId") != null && !"".equals(arg2.getParameter("userId"))){
//			systemUserDepartmentList = systemUserDepartmentBo.selectByUserId(Integer.parseInt(arg2.getParameter("userId")) );
//			User user = new User();
//			user.setUsername("admin");
//			arg2.getSession().setAttribute("user", user);
//			
//		}else{
//			systemUserDepartmentList = systemUserDepartmentBo.selectByUserId(SessionUser.getUser(arg2).getUser_id());
//		} 
//		for (TSystemUserDepartment systemUserDepartment : systemUserDepartmentList) {
//			String departmentId = systemUserDepartment.getDepartmentId();
//			TSystemDepartment systemDepartment = departmentBo.findById(departmentId);
//			if(systemDepartment.getIsZhiShu() != null){
//				return arg0.findForward("selectonedoczhishu");	
//			}
//		}
		return arg0.findForward("selectonedoc");
	}
	public ActionForward fengfaselectonedoc(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);	
		
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("fengfaselectonedoc");
	}
	
	/**
	 * 进入修改发文内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward updatedocform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		String node =  workFlowTemplate.selectNodeName( xingzhengfawenNeirong.getFlowid().longValue());
		if("封发".equals(node)){
			arg2.getSession().setAttribute("isfenfa", 1);
		}else{
			arg2.getSession().setAttribute("isfenfa", 0);
		}
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("updatedocform");
	}
	public ActionForward fengfaupdatedocform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		String node =  workFlowTemplate.selectNodeName( xingzhengfawenNeirong.getFlowid().longValue());
		if("封发".equals(node)){
			arg2.getSession().setAttribute("isfenfa", 1);
		}else{
			arg2.getSession().setAttribute("isfenfa", 0);
		}
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("fengfaupdatedocform");
	}
	/**
	 * 修改正文后的处理
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward updatedoc(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		addXingzhengfawenyijian(arg2,"修改正文");
		arg2.setAttribute("linkurl", "documentationflow/xingzhengfawen/xingzhengflowgenzong.jsp");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 进入修改发文内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward updateform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("updateform");
	}
	public ActionForward fengfaupdateform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("fengfaupdateform");
	}
	/**
	 * 进入归档发文界面
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward guidangform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("guidangform");
	}
	
	
	/**
	 * 进入修改发文内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward update(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		xingzhengfawenNeirong.setBiaoti(arg2.getParameter("zhaiyao"));
		xingzhengfawenNeirong.setFujian(arg2.getParameter("fujian"));
//		xingzhengfawenNeirong.setWenhaotype(arg2.getParameter("numbertype"));		
		xingzhengfawenNeirong.setFenshu(arg2.getParameter("fenshu"));		
		xingzhengfawenNeirong.setChaosong(arg2.getParameter("chaosongname"));
		xingzhengfawenNeirong.setZhusong(arg2.getParameter("zhusongname"));
		//处理文种
		String wentypeid = arg2.getParameter("wentype");
		SubTypeInfo subtype = wenTypeBO.selectSubTypeById(Integer.valueOf(wentypeid)).get(0);
		xingzhengfawenNeirong.setWentype(subtype.getTypeName());
		xingzhengfawenNeirong.setTemptype(subtype.getTempName());
		xingzhengfawenNeirong.setHaotype(subtype.getWenhaotype());
		xingzhengfawenNeirong.setWenhaotype(subtype.getWenhaotype());
		
		String wenhaostr = arg2.getParameter("wenhao"); 
		if (wenhaostr != null && !"null".equals(wenhaostr)){
			Integer wenhao  =  Integer.parseInt(wenhaostr) ;
			xingzhengfawenNeirong.setWenhao(wenhao);
			xingzhengfawenNeirong.setWenhaonumber(wenhaostr);
			if (subtype.getWenhaotype().indexOf("第期") != -1) {
				xingzhengfawenNeirong.setWenhaotype("第"+wenhaostr+"期");
			}else{
				String wenyear = arg2.getParameter("wenyear");
				xingzhengfawenNeirong.setWenyear(Integer.parseInt(wenyear) );
				xingzhengfawenNeirong.setWenhaotype(subtype.getWenhaotype()+ "〔" +wenyear+"〕" +wenhaostr+"号");
			}
		}	
		
		xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
		arg2.setAttribute("linkurl", "documentationflow/xingzhengfawen/xingzhengflowgenzong.jsp");				
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	
	
	/**
	 * 进入修改附件内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward updatefujianform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub		
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("updatefujianform");
	}
	public ActionForward fengfaupdatefujianform(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub		
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("fengfaupdatefujianform");
	}
	
	/**
	 * 修改附件内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward updatefujian(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub		
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		List<TXingzhengfawenFujian> list = new ArrayList<TXingzhengfawenFujian>(xingzhengfawenNeirong.getTXingzhengfawenFujians());
		for (TXingzhengfawenFujian xingzhengfawenFujian : list) {
			xingzhengfawenFujianBO.delteFuJian(xingzhengfawenFujian);
		}
		MessageResources message=getResources(arg2);
		String fromFilePath=message.getMessage(arg2.getLocale(), "system.uploadFile.tempFilePath");
		String toFilePath = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengfawen/properties/systemResource.properties", this).getProperty("xingzhengfawen.fileurl");
		List<Files> fileList=DealString.fileCopyTofile(arg2, fromFilePath, toFilePath);
		for (Iterator iterator = fileList.iterator(); iterator.hasNext();) {
			Files file = (Files) iterator.next();
			TXingzhengfawenFujian xingzhengshouwenFujian = new TXingzhengfawenFujian();
			xingzhengshouwenFujian.setFujianAddress(file.toFilePath);
			xingzhengshouwenFujian.setFujianName(file.getOldFileName());
			xingzhengshouwenFujian.setFujianZhengname(file.getNewFileName());
			xingzhengshouwenFujian.setXingzhengfawenNeirong(xingzhengfawenNeirong);
			xingzhengfawenFujianBO.addFuJian(xingzhengshouwenFujian);
			
		}
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	
	/**
	 * 归档
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward guidang(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		File   dir   =   new   File("D:\\guidang\\xingzhengfawen\\"); 
		if(!dir.exists()){
			dir.mkdirs();
		}
		/**
		 * 创建归档文件目录
		 */
		String year = String.valueOf(xingzhengfawenNeirong.getFawendatetime().getYear()+1900);
		String month = String.valueOf(xingzhengfawenNeirong.getFawendatetime().getMonth()+1);
		String number = xingzhengfawenNeirong.getWenhaonumber();
		File   fileDir = new   File("D:\\guidang\\xingzhengfawen\\"+year+"\\"+month+"\\"+number+"\\");
		if(!fileDir.exists()){
			fileDir.mkdirs();
		}
		/**
		 * 拷贝正文
		 */
		String strDirPath = arg2.getSession().getServletContext().getRealPath("/");
		String oldPath = strDirPath + "documentationflow\\xingzhengfawen\\docs\\"+xingzhengfawenNeirong.getDocname();
		String newPath = "D:\\guidang\\xingzhengfawen\\"+year+"\\"+month+"\\"+number+"\\"+xingzhengfawenNeirong.getDocname();
		FileManage.copyFile(oldPath, newPath); 
		
		/**
		 * 拷贝附件
		 */
		if(xingzhengfawenNeirong.getTXingzhengfawenFujians().size() > 0){
			List<TXingzhengfawenFujian> fuJianList = new ArrayList<TXingzhengfawenFujian>(xingzhengfawenNeirong.getTXingzhengfawenFujians());
			for (TXingzhengfawenFujian xingzhengfawenFujian : fuJianList) {
				oldPath = xingzhengfawenFujian.getFujianAddress();
				newPath = "D:\\guidang\\xingzhengfawen\\"+year+"\\"+month+"\\"+number+"\\"+xingzhengfawenFujian.getFujianName();
				FileManage.copyFile(oldPath, newPath); 
			}
			
		}
		
		/**
		 * 生成承办单文件		 */
		String html = arg2.getParameter("html");
		FileManage fileManage = new FileManage();		
		fileManage.newFile("D:\\guidang\\xingzhengfawen\\"+year+"\\"+month+"\\"+number+"\\"+"承办单.html", html);		
		
		xingzhengfawenNeirong.setIsguidang(1);
		xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
		
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	
	/**
	 * 导出发文内容
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward daochu(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(arg2.getParameter("id"));
		Date date = workFlowTemplate.processInstanceDate(Long.valueOf(xingzhengfawenNeirong.getFlowid()) );
		xingzhengfawenNeirong.setQiChaoShiJian(date);
		String fubenname = addFuben(xingzhengfawenNeirong.getDocname());
		arg2.setAttribute("fubenname", fubenname);
		return arg0.findForward("daochu");
	}
	
	
	
	/**
	 * 添加经手人	 * @param request
	 * @param docid
	 */
	private void addJingShouRen(HttpServletRequest request, String docid) {
		TXingzhengfawenNeirong xingzhengfawenNeirong;
		xingzhengfawenNeirong = xingzhengfawenNeirongBO.selectOneById(docid);
		if(xingzhengfawenNeirong.getJingshouren() == null)
		{
			xingzhengfawenNeirong.setJingshouren(","+SessionUser.getUser(request).getUser_id()+",");
			xingzhengfawenNeirong.setJingshoubumen(SessionUser.getUser(request).getDepartment());
		}
		else
		{
			xingzhengfawenNeirong.setJingshouren(xingzhengfawenNeirong.getJingshouren()+SessionUser.getUser(request).getUser_id()+",");
			xingzhengfawenNeirong.setJingshoubumen(xingzhengfawenNeirong.getJingshoubumen()+SessionUser.getUser(request).getDepartment()+",");
		}
		xingzhengfawenNeirongBO.updateTXingzhengfawenneirong(xingzhengfawenNeirong);
	}
	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}
	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}
	public ITXingzhengfawendengjibuBO getXingzhengfawendengjibuBO() {
		return xingzhengfawendengjibuBO;
	}
	public void setXingzhengfawendengjibuBO(
			ITXingzhengfawendengjibuBO xingzhengfawendengjibuBO) {
		this.xingzhengfawendengjibuBO = xingzhengfawendengjibuBO;
	}
	
	public List<TXingzhengfawenNeirong> selectFaWenSuperdaiban(HttpServletRequest arg2){
		return null;
	}
	

	/**
	 * 删除文件和待办
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward deleteDoc(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		String id = arg2.getParameter("id");
		Integer taskId = Integer.parseInt(arg2.getParameter("taskid"));
		xingzhengfawenNeirongBO.deleteTask(taskId);
		xingzhengfawenNeirongBO.deleteOneById(id);
		
		arg2.setAttribute("linkurl", "tjsinfo/tjsoa/xingzhengfawen/fawenadmin.do");
		arg2.setAttribute("message", "com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.message");
		return arg0.findForward("success");
	}
	
	/**
	 * 最小年份
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @return
	 * @throws Exception
	 */
	public ActionForward selectwenyear(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		Integer minyear =   xingzhengfawenNeirongBO.wenyearmin();
		Integer maxyear =   xingzhengfawenNeirongBO.wenyearmax();
		JSONObject object = new JSONObject();
		object.put("max", maxyear);
		object.put("min", minyear);
		arg3.getWriter().print(object);
		return null;
	}
	
	public ActionForward getMaxTypeNumber(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		String wentypeid = arg2.getParameter("wentypeid");
		Integer id=Integer.parseInt(wentypeid);
		List<SubTypeInfo> subtypelist = wenTypeBO.selectSubTypeById(id);
		if (subtypelist.size()>0){
			Integer number  = xingzhengfawenNeirongBO.selectXingzhengfawenMaxNumber(subtypelist.get(0).getTypeName());
			JSONObject object = new JSONObject();
			object.put("number", number);
			object.put("haotype", subtypelist.get(0).getWenhaotype());
			arg3.getWriter().print(object);
		}
		return null;
	}
	
	public ActionForward print(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		TXingzhengfawenNeirong xingzhengfawenNeirong = xingzhengfawenNeirongBO
				.selectOneById(arg2.getParameter("id"));
		arg2.setAttribute("xingzhengfawenNeirong", xingzhengfawenNeirong);
		return arg0.findForward("print");
	}
	
	public ActionForward getYuezhiList(ActionMapping arg0, ActionForm arg1,
			HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
		// TODO Auto-generated method stub
		Long flowid = Long.valueOf(arg2.getParameter("flowid"));
		PaginationSupport paginationSupport = null;
		List<Taskinstance> list;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		paginationSupport =  taskInstanceBO.selectNodeTask(flowid, "封发", 0 , 300 );
		//Integer totalProperty = paginationSupport.getTotalCount();
		list = paginationSupport.getItems();
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			Taskinstance taskinstance = (Taskinstance)iterator.next();
			JSONObject taskObject = new JSONObject();
			taskObject.put("username", taskinstance.getTjsUser().getUserName());
			taskObject.put("time", ToolKit.getFormatDate(taskinstance.getEnd(), "yyyy-MM-dd HH:mm"));
			array.put(taskObject);
		}
		arg3.getWriter().print(array);
		return null;
	}
	
}
